package cn.onein.edu.web.dao;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Service;

import cn.onein.edu.biz.bean.User;

/**
 * 用户登录DAO
 * 
 * @author Upton
 * 
 */
@Service
public class LoginDao {
	
	@Autowired
	private SqlMapClientTemplate sqlMapClientTemplate;

	/**
	 * 用户登录
	 * 
	 * @param userName
	 * @param password
	 * @return
	 */
	public User queryUser(String userName, String password) {
		Map<String, Object> param = new HashMap<String, Object>();

		param.put("userName", userName);
		param.put("password", password);

		User user = (User) sqlMapClientTemplate.queryForObject("queryUser",	param);

		return user;
	}

	/**
	 * 更新用户登录信息
	 * @param id
	 * @param lastIP
	 */
	public void updateUserLoginInfo(Long id, String lastIP) {
		Map<String, Object> param = new HashMap<String, Object>();

		param.put("id", id);
		param.put("lastIP", lastIP);
		
		sqlMapClientTemplate.update("updateUserLoginInfo", param);
	}
	
	/**
	 * 忘记密码
	 * 
	 * @param userName
	 * @param password
	 * @return
	 */
	public User queryUserByName(String userName) {
		Map<String, Object> param = new HashMap<String, Object>();

		param.put("userName", userName);

		User user = (User) sqlMapClientTemplate.queryForObject("queryUserByName",	param);

		return user;
	}
	
	/**
	 * 修改密码
	 * 
	 * @param userName
	 * @param password
	 * @return
	 */
	public void updateUserPassword(Map<String,Object> param) {

		sqlMapClientTemplate.update("updateUserPassword", param);
	}
}
